package cool.taomu.box.jsch.test.spring

import com.google.inject.Guice
import cool.taomu.box.guice.TaomuGuiceModule
import cool.taomu.box.jsch.Ssh
import cool.taomu.box.jsch.test.AProvider
import org.junit.Test
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig
import cool.taomu.box.jsch.SshSpringConfigure

@Configuration
@ComponentScan("cool.taomu.box.*")
class SpringConfigure extends SshSpringConfigure{

	@Bean
	def module(){
		new TaomuGuiceModule().build(AProvider)	
	}
}

@SpringJUnitConfig
class SpringTests {
	
	@Test
	def void contextLoads() {
		var ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfigure);
		var Ssh ssh = applicationContext.getBean(Ssh);
		var res = ssh.exec("ls -l", "UTF-8");
		println(res)
		ssh.close
		
		ssh = applicationContext.getBean(Ssh);
		res = ssh.exec("ls -l", "UTF-8");
		println(res)
		ssh.close
	}
}
